import React from 'react';
import { connect } from 'dva';
import FastFilterComponent from '../../components/Common/FastFilter/FastFilter';

function FastFilter({ dispatch, ...props }) {
  const fastFilterProps = {
    ...props,
    onFormData: getFormData, /* 快捷搜索 */
    onAddFastData: addFastData, /* 新增快捷过滤模板 */
    onDelFastData: delFastData, /* 删除快捷过滤模板 */
  };

  function getFormData(componentName, dataUrl, value, fastbFilter) {
    dispatch({
      type: 'mergeTable/getFormData',
      payload: {
        componentName, dataUrl, value, fastbFilter, isSearch: true,
      },
    });
  }

  function addFastData(value, addUrl, fConfig) {
    /* 新增快捷过滤模板 */
    dispatch({ type: 'fastFilter/addFastData', payload: { value, addUrl, fConfig } });
  }

  function delFastData(delUrl, fConfig) {
    /* 删除快捷过滤模板 */
    dispatch({ type: 'fastFilter/delFastData', payload: { delUrl, fConfig } });
  }

  return (
    <FastFilterComponent {...fastFilterProps} />
  );
}

export default connect(({ app }) =>
  ({ app }))(FastFilter);
